package com.xhj.joffer.array;
import org.junit.Test;

import java.util.Arrays;
/**
 * @author haijianxia pure_xhj@163.com
 * @Date 2021-09-16
 * @Time 11:46
 */
public class SortToOddEven {
  public static void main(String[] args) {
	  int[] array=new int[]{1,3,4,5,8,8,9,11,15};
	  int[] arraySort = test01(array);
    System.out.println(Arrays.toString(arraySort));
  }
  /** 思路一: 遍历 */
  @Test
  public static int[] test01(int[] array) {
  	System.out.println("\n=============test01==============");
  	System.out.println("思路一: 遍历");
  	long time01 = System.currentTimeMillis();

  	int[] result =new int[array.length];
	  int indexResult=0;
    for (int i = 0; i < array.length; i++) {
	    if (array[i]%2==1){
		    result[indexResult++]=array[i];
	    }
    }
    for (int i = 0; i < array.length; i++) {
	    if (array[i]%2==0){
		    result[indexResult++]=array[i];
	    }
    }

  	long time0101  = System.currentTimeMillis() - time01;
  	System.out.println("test01 耗时 =  " + time0101  + "ms");
  	System.out.println("=================================");

  	return result;
  }
}
